package com.studentManagement.serviceImpl;

import com.studentManagement.daoImpl.StudentDaoImpl;
import com.studentManagement.po.Student;
import com.studentManagement.po.Student_simple;
import com.studentManagement.service.StudentService;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by free on 2017/7/7.
 */
public class StudentServiceImpl implements StudentService {
    //为了getTips_10方法，判断某字符串是已经存在list中
    private boolean canAddToList_forGetTip10(List<String> list,String str){
        boolean b=true;
        for (int i = 0; i <list.size() ; i++) {
            if(list.get(i).toString().equals(str)){
                b=false;
            }
        }
        return b;
    }
    @Override //关键词搜索的提示内容
    public List<String> getTips_10(String keywords) {
        List<Student> studentDetail=new StudentDaoImpl().getStudentDetail_byKeywords(keywords,1,10);
        List<String> list=new ArrayList<>();
        for (int i = 0; i <studentDetail.size() ; i++) {
            if(studentDetail.get(i).getStudent_id()!=null&&studentDetail.get(i).getStudent_sex()!=null&&studentDetail.get(i).getStudent_name()!=null&&studentDetail.get(i).getStudent_qq()!=null&&studentDetail.get(i).getStudent_duty()!=null&&studentDetail.get(i).getStudent_dormitory_id()!=null&&studentDetail.get(i).getStudent_phone()!=null&&studentDetail.get(i).getStudent_address()!=null){
                if(studentDetail.get(i).getStudent_id().contains(keywords)&&canAddToList_forGetTip10(list,studentDetail.get(i).getStudent_id())){
                    list.add(studentDetail.get(i).getStudent_id());
                    if (list.size()>=10) break;
                }
                if(studentDetail.get(i).getStudent_name().contains(keywords)&&canAddToList_forGetTip10(list,studentDetail.get(i).getStudent_name())){

                    list.add(studentDetail.get(i).getStudent_name());
                    if (list.size()>=10) break;
                }
                if(studentDetail.get(i).getStudent_sex().contains(keywords)&&canAddToList_forGetTip10(list,studentDetail.get(i).getStudent_sex())){
                    list.add(studentDetail.get(i).getStudent_sex());
                    if (list.size()>=10) break;
                }
                if(studentDetail.get(i).getStudent_phone().contains(keywords)&&canAddToList_forGetTip10(list,studentDetail.get(i).getStudent_phone())){
                    list.add(studentDetail.get(i).getStudent_phone());
                    if (list.size()>=10) break;
                }
                if(studentDetail.get(i).getStudent_address().contains(keywords)&&canAddToList_forGetTip10(list,studentDetail.get(i).getStudent_address())){
                    list.add(studentDetail.get(i).getStudent_address());
                    if (list.size()>=10) break;
                }
                if(studentDetail.get(i).getStudent_qq().contains(keywords)&&canAddToList_forGetTip10(list,studentDetail.get(i).getStudent_qq())){
                    list.add(studentDetail.get(i).getStudent_qq());
                    if (list.size()>=10) break;
                }
                if(studentDetail.get(i).getStudent_dormitory_id().contains(keywords)&&canAddToList_forGetTip10(list,studentDetail.get(i).getStudent_dormitory_id())){
                    list.add(studentDetail.get(i).getStudent_dormitory_id());
                    if (list.size()>=10) break;
                }
                if(studentDetail.get(i).getStudent_duty().contains(keywords)&&canAddToList_forGetTip10(list,studentDetail.get(i).getStudent_duty())){
                    list.add(studentDetail.get(i).getStudent_duty());
                    if (list.size()>=10) break;
                }
            }
        }
        return list;
    }

//    @Override
//    public List<Student_simple> getStudent_simple_keywords(String keywords, int pageNum, int onePage) {
//        List<Student_simple> simples=new ArrayList<>();
//        List<Student> students=new StudentDaoImpl().getStudentDetail_byKeywords(keywords,pageNum,onePage);
//
//        return null;
//    }
}
